package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqEnumField;
import cloud.maque.admin.service.MqEnumFieldService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 字典字段接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/enum/field")
@Api(tags = "运维-字典字段接口")
public class EnumFieldController {

    @Autowired
    MqEnumFieldService fieldService;


    @PostMapping("/list")
    @ApiOperation(value = "字段查询")
    @TenantQuery
    public ResponseBodyVo<PageInfo<MqEnumField>> Page(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqEnumField> pageReq) {
        return ResponseBodyVo.Success(fieldService.page(pageReq));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "字段详情")
    public ResponseBodyVo<MqEnumField> Detail(@RequestParam("id") String id) {
        return ResponseBodyVo.Success(fieldService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存字段")
    public ResponseBodyVo<MqEnumField> Save(@RequestBody MqEnumField enumField) {
        return ResponseBodyVo.Success(fieldService.Save(enumField));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除字段")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@PathVariable("id") String fieldId, @TenantId String tenantId) {
        return ResponseBodyVo.Success(fieldService.delete(fieldId,tenantId));
    }


}
